package org.travel_system.service.impl;

import org.travel_system.mapper.UserMapper;
import org.travel_system.pojo.User;
import org.travel_system.service.UserService;
import org.travel_system.utils.Md5Util;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl implements UserService {

    private final UserMapper userMapper;

    @Autowired
    public UserServiceImpl(UserMapper userMapper) {
        this.userMapper = userMapper;
    }

    @Override
    public User findUserByName(String username) {
        return userMapper.findByUserName(username);
    }

    @Override
    public int register(String username, String password) {
        //加密
        String md5String = Md5Util.getMD5String(password);
        //添加
        return userMapper.add(username,md5String);
    }

    @Override
    public int update(Integer id, User user) {
        user.setId(id);
        return userMapper.update(user);
    }

    @Override
    public int updatePwd(Integer id, String newPwd) {
        return userMapper.updatePwd(Md5Util.getMD5String(newPwd),id);
    }

    @Override
    public Integer findUserId(String username) {
        return userMapper.findUserId(username);
    }

}
